<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%
    if (session.getAttribute("loggedIn") != null) 
    {
        if (((Boolean) session.getAttribute("loggedIn"))) 
        {
            if (session.getAttribute("role").equals("courier")) 
            {
                response.sendRedirect("courier_shipments.jsp");
            } 
            else if (!session.getAttribute("role").equals("admin")) 
            {
                response.sendRedirect("index.jsp");
            }
        } else {
            response.sendRedirect("index.jsp");
        }
    } else {
        response.sendRedirect("index.jsp");
    }
%>



<s:layout-render name="/managerlayout.jsp" headline="Delivery Service">
    <s:layout-component name="body">
        <s:useActionBean var="actionBean" beanclass="cz.muni.fi.pa165.web.ManagerCourierActionBean" />
        <h2 style="text-align: center;" class="listHeadline"><f:message key="fcourierlist"/></h2>
        <s:link style="margin: 1%; float:right;" href="/newCourier.jsp" class="btn btn-mini btn-primary"><f:message key="addnewcourier"/></s:link>
            <table class="table table-hover">
                <tr>
                    <th><f:message key="fid"/></th>
                <th><f:message key="ffirstname"/></th>
                <th><f:message key="flastname"/></th>
                <th><f:message key="fusername"/></th>
                <th><f:message key="/CustomerManager.addcourier.edit"/></th>
                <th><f:message key="/CustomerManager.addcourier.delete"/></th>
            </tr>
            <c:forEach items="${actionBean.couriers}" var="courier">
                <tr>
                    <td><c:out value="${courier.id}"/></td>
                    <td><c:out value="${courier.firstName}"/></td>
                    <td><c:out value="${courier.lastName}"/></td>
                    <td><c:out value="${courier.userName}"/></td>
                    <td><s:link class="btn btn-small" beanclass="cz.muni.fi.pa165.web.ManagerCourierActionBean" event="edit" href="/editCouriers.jsp">
                            <s:param name="courier.id" value="${courier.id}"/>
                            <f:message key="/CustomerManager.addcourier.edit"/>
                        </s:link>
                    </td>
                    <td><s:link class="btn btn-small btn-danger" beanclass="cz.muni.fi.pa165.web.ManagerCourierActionBean" event="delete">
                            <s:param name="courier.id" value="${courier.id}"/>
                            <f:message key="/CustomerManager.addcourier.delete"/>
                        </s:link>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </s:layout-component>
</s:layout-render>
